package huoye.shops.huoye.operation.fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.codeideology.android.lang.entity.Paging;
import com.codeideology.android.widget.recycler.RecyclerViewAdapter;

import huoye.shops.R;
import huoye.shops.base.BaseActivity;
import huoye.shops.base.PullToRefreshFragment;
import huoye.shops.huoye.operation.activity.DiscountCancelActivity;
import huoye.shops.huoye.operation.adapter.DiscountCancelAdapter;
import huoye.shops.huoye.operation.adapter.ManageEventAdapter;
import huoye.shops.huoye.operation.model.DiscountCancelData;
import huoye.shops.huoye.operation.model.ManageEventData;
import huoye.shops.huoye.operation.presenter.DiscountCancelPresenter;
import huoye.shops.huoye.operation.view.IDiscountCancelRefreshView;
import huoye.shops.huoye.operation.view.IManageEventRefreshView;


public class DiscountCancelFragment extends PullToRefreshFragment<DiscountCancelData> implements IDiscountCancelRefreshView {

    public static final int TYPE_DISCOUNT_CANCEL_NO  = 0; //未核销
    public static final int TYPE_DISCOUNT_CANCEL_YES = 1; //已核销


    private int mType;
    private DiscountCancelPresenter mDiscountCancelPresenter;

    @Override
    public RecyclerViewAdapter createAdapter() {

        Bundle bundle = getArguments();
        mType = bundle.getInt(BaseActivity.EXTRAS_KEY_DATA);
        DiscountCancelAdapter adapter = new DiscountCancelAdapter(getActivity());

        return adapter;
    }

/*    @Override
    protected void onShowFragment() {
        super.onShowFragment();
        query();
    }*/

    @Override
    protected void initView(View view, @Nullable Bundle bundle) {
        super.initView(view, bundle);

        mDiscountCancelPresenter = new DiscountCancelPresenter();
        mDiscountCancelPresenter.addTaskListener(this);
        mDiscountCancelPresenter.onStart();

        query();
        setNoNumber();

    }

    private void  setNoNumber(){
        DiscountCancelActivity activity = (DiscountCancelActivity)getActivity();
        activity.setNoDiscountCanceNumber("10");
    }


    @Override
    public void query(Paging paging) {
        super.query(paging);
        if(mType == TYPE_DISCOUNT_CANCEL_NO){
            mDiscountCancelPresenter.getShopDiscountList(TYPE_DISCOUNT_CANCEL_NO+"",paging);
        }else {
            mDiscountCancelPresenter.getShopDiscountList(TYPE_DISCOUNT_CANCEL_YES+"",paging);

        }

    }


    public static DiscountCancelFragment getInstan(int type) {
        DiscountCancelFragment fragment = new DiscountCancelFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(BaseActivity.EXTRAS_KEY_DATA, type);
        fragment.setArguments(bundle);
        return fragment;

    }




    @Override
    public void onItemClick(DiscountCancelData discountCancelData, int i, View view) {

    }

}
